home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -in_the_mag- / assembler / test.s < prev    next >
Text File  |  1997-11-21  |  3KB  |  130 lines

  1. * --------------------------------------------------------------------
  2. * test.s
  3. * --------------------------------------------------------------------
  4.  
  5. ; this initial material would normaly be provided as a separate header 
  6. ; file - it provides the _LVO values for the functions being used 
  7. ; together with the macros used by the program...
  8.  
  9. _AbsExecBase         EQU    4
  10.  
  11. _LVOOpenLibrary      EQU -552
  12.  
  13. _LVOCloseLibrary     EQU -414
  14.  
  15. _LVOOutput           EQU  -60  
  16.  
  17. _LVOWrite            EQU  -48
  18.  
  19. NULL                 EQU    0
  20.  
  21. LF                   EQU   10
  22.  
  23.                      XDEF _main
  24.  
  25. LINKLIB MACRO
  26.    
  27.          IFGT NARG-2
  28.  
  29.            FAIL   ;too many arguments
  30.  
  31.          ENDC
  32.     
  33.          move.l   a6,-(sp)
  34.    
  35.          move.l   \2,a6
  36.    
  37.          jsr      \1(a6)
  38.    
  39.          move.l (sp)+,a6
  40.    
  41.          ENDM
  42.  
  43.  
  44. CALLSYS  MACRO
  45.  
  46.          LINKLIB _LVO\1,\2
  47.     
  48.          ENDM
  49.  
  50.  
  51. WRITEDOS MACRO
  52.  
  53.          movem.l  d1-d3,-(sp)               preserve registers d1-d3
  54.          
  55.          move.l   \2,d1                     DOS output file handle
  56.          
  57.          move.l   #\1,d2                    start of message 
  58.          
  59.          move.l   #\1_SIZEOF,d3             size of message
  60.          
  61.          CALLSYS  Write,_DOSBase            DOS call to write message
  62.          
  63.          movem.l  (sp)+,d1-d3               restore registers d1-d3
  64.     
  65.          ENDM
  66.  
  67. * --------------------------------------------------------------------
  68.  
  69. ; The following stuff is the program itself...
  70.  
  71.  
  72.      
  73. _main    move.l   _AbsExecBase,_SysBase      set up SysBase variable
  74.  
  75.          lea      dos_name,a1                library name start in a1
  76.     
  77.          moveq    #0,d0                      any version will do
  78.     
  79.          CALLSYS  OpenLibrary,_SysBase       macro (see article for details)
  80.     
  81.          move.l   d0,_DOSBase                store returned value
  82.  
  83.          beq      EXIT                       quit if NULL
  84.  
  85. ; if we reach here the DOS library is open and functions can be used...
  86.  
  87.          CALLSYS  Output,_DOSBase            get default output handle
  88.          
  89.          move.l   d0,_stdout                 store output handle 
  90.  
  91.          beq      CLOSELIB
  92.  
  93. ; have obtained valid output handle so message can be written...
  94.  
  95.          WRITEDOS message,_stdout            get DOS to write message
  96.  
  97.  
  98. ; all done so now we can close DOS library...
  99.  
  100. CLOSELIB move.l   _DOSBase,a1                base needed in a1        
  101.     
  102.          CALLSYS  CloseLibrary,_SysBase
  103.     
  104.     
  105. ; and terminate the program...    
  106.  
  107. EXIT     clr.l    d0
  108.          
  109.          rts                                 logical end of program
  110.         
  111. * --------------------------------------------------------------------    
  112. ; these are all the variables and static data...
  113.  
  114. _stdout           ds.l    1
  115.  
  116. _SysBase          ds.l    1
  117.  
  118. _DOSBase          ds.l    1
  119.     
  120. dos_name          dc.b 'dos.library',NULL
  121.     
  122. message           dc.b 'Amiga Format Rules OK!',LF
  123.     
  124. message_SIZEOF    EQU *-message
  125.  
  126.                   END
  127.                       
  128. * --------------------------------------------------------------------
  129.  
  130.